package com.rpc.core.codec.adapter;

import com.rpc.core.codec.RpcCodec;
import io.netty.buffer.ByteBuf;
import io.netty.channel.ChannelHandler;
import io.netty.channel.ChannelHandlerContext;
import io.netty.handler.codec.MessageToByteEncoder;

public class NettyEncodeAdapter extends MessageToByteEncoder<Object> {


    private RpcCodec codec;

    public NettyEncodeAdapter(RpcCodec codec) {
        this.codec = codec;
    }

    @Override
    protected void encode(ChannelHandlerContext channelHandlerContext, Object o, ByteBuf byteBuf) throws Exception {
        codec.serialize(o,byteBuf);
    }
}
